package plotter;

import javax.swing.*;
import java.awt.*;

class ColorButtonPanel extends JPanel
{
	private Color color = Color.BLACK;
	
	public ColorButtonPanel(Color color) {
		this.color = color;
	}
	public void setColor(Color c) {
		color = c;
		repaint();
	}
	public Color getColor() {
		return color;
	}
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		Rectangle r = this.getVisibleRect();
		g.setColor(color);
		g.fill3DRect(r.x, r.y, r.width, r.height, true);
	}
}

class ColorButton extends JButton
{
	private ColorButtonPanel panel;
	
	public ColorButton(Color color) {
		if (color == null)
			panel = new ColorButtonPanel(Color.BLACK);
		else
			panel = new ColorButtonPanel(color);
		add(panel);
	}
	public void setColor(Color c) 
	{
		panel.setColor(c);
	}
	public Color getChosenColor() {
		Color c = JColorChooser.showDialog(this, "Choose color", panel.getColor());
		if (c != null) {
			panel.setColor(c);
			return c;
		}
		return null;
	}
}

